package udpserver

import (
	"fmt"
	"github.com/garyburd/redigo/redis"
	"runtime"
)

var conn redis.Conn

//初始化redis连接
func init(){

	var err2 error
	conn, err2 = redis.Dial("tcp", "192.168.1.109:6379")
	if err2 != nil {
		fmt.Println(err2)
		//log.Debug(err2)
	}
}


//这里的操作是将gps数据发布到redis,发送给前端
//并写到任务队列，写到数据库
func Handlecapinfo(info string){
	//fmt.Println("处理安全帽数据")
	//加到redis任务队列
	_,err1 := conn.Do("PUBLISH", "channel2", info)
	if err1 != nil {
		fmt.Println("pub err: ", err1)
		return
	}

	payLoad := Payload{Num: 1, Info:info}
	work := Job{Payload: payLoad}
	// 任务放入任务队列channal
	JobQueue <- work
	//fmt.Println("队列总长度:",cap(JobQueue))
	//fmt.Println("队列未消费任务数量:",len(JobQueue))
	//fmt.Println("JobQueue <- work")
	FileLogs.Info("当前协程数:", runtime.NumGoroutine())
}